package com.qidian.buy.product.receive;

import com.qidian.buy.entity.Item;
import com.qidian.buy.entity.ItemDesc;
import com.qidian.buy.product.service.IItemService;
import com.qidian.buy.util.pojo.BuyResult;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @Author 戴着假发的程序员
 * @Company 起点编程
 * @date 2023/5/25 14:01
 */
@Component
public class ItemAddReceive {
    @Autowired
    private IItemService itemService;
    @RabbitListener(queues = "item-detail-queue")
    public void genDetailHtml(Long itemId){
        // 理论上这里是要远程调用的，但是我们的商品详情和后台管理在同一个工程中，就不需要远程调用了
        BuyResult buyResult = itemService.queryById(itemId);
        Map map = (Map) buyResult.getObj();
        //  调用service的方法生成静态页面
        itemService.genHtml((Item) map.get("item"), (ItemDesc) map.get("itemDesc"));
    }
}
